<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"he7009.gitee.io","root":"/","scheme":"Mist","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="docker-compose.yml 文件部分命令说明    build 指定 Dockerfile 所在文件夹路径    container_name 指定容器名称   depends_on 指定多个服务之间的依赖关系，启动时会先启动被依赖服务   entrypoint 覆盖容器中默认的入口命令   environment 设置环境变量   image 指定为镜像名称或镜像ID，如果本地镜像不存">
<meta property="og:type" content="article">
<meta property="og:title" content="Docker-Compose 构建 lnmp 环境">
<meta property="og:url" content="https://he7009.gitee.io/2021/03/27/docker/docker-compose-chang-yong-ming-ling/index.html">
<meta property="og:site_name" content="he7009">
<meta property="og:description" content="docker-compose.yml 文件部分命令说明    build 指定 Dockerfile 所在文件夹路径    container_name 指定容器名称   depends_on 指定多个服务之间的依赖关系，启动时会先启动被依赖服务   entrypoint 覆盖容器中默认的入口命令   environment 设置环境变量   image 指定为镜像名称或镜像ID，如果本地镜像不存">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-03-27T10:25:10.000Z">
<meta property="article:modified_time" content="2021-03-27T10:27:44.293Z">
<meta property="article:author" content="he7009">
<meta property="article:tag" content="lnmp">
<meta property="article:tag" content="docker-compose">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://he7009.gitee.io/2021/03/27/docker/docker-compose-chang-yong-ming-ling/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Docker-Compose 构建 lnmp 环境 | he7009</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="he7009" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">he7009</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">天行健，君子以自强不息</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tag fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-commonweal">

    <a href="/404/" rel="section"><i class="fa fa-heartbeat fa-fw"></i>公益 404</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://he7009.gitee.io/2021/03/27/docker/docker-compose-chang-yong-ming-ling/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="he7009">
      <meta itemprop="description" content="Go、PHP、Mysql、Redis、Linux、Shell、Nginx—知识分享">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="he7009">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Docker-Compose 构建 lnmp 环境
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2021-03-27 18:25:10 / 修改时间：18:27:44" itemprop="dateCreated datePublished" datetime="2021-03-27T18:25:10+08:00">2021-03-27</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Docker/" itemprop="url" rel="index"><span itemprop="name">Docker</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="docker-compose-yml-文件部分命令说明"><a href="#docker-compose-yml-文件部分命令说明" class="headerlink" title="docker-compose.yml 文件部分命令说明"></a>docker-compose.yml 文件部分命令说明</h2><hr>
<table>
<thead>
<tr>
<th>build</th>
<th>指定 Dockerfile 所在文件夹路径</th>
</tr>
</thead>
<tbody><tr>
<td>container_name</td>
<td>指定容器名称</td>
</tr>
<tr>
<td>depends_on</td>
<td>指定多个服务之间的依赖关系，启动时会先启动被依赖服务</td>
</tr>
<tr>
<td>entrypoint</td>
<td>覆盖容器中默认的入口命令</td>
</tr>
<tr>
<td>environment</td>
<td>设置环境变量</td>
</tr>
<tr>
<td>image</td>
<td>指定为镜像名称或镜像ID，如果本地镜像不存在，Compose会尝试拉取这个镜像</td>
</tr>
<tr>
<td>networks</td>
<td>所加入的网络</td>
</tr>
<tr>
<td>ports</td>
<td>端口映射</td>
</tr>
<tr>
<td>volumes</td>
<td>数据卷路径映射</td>
</tr>
<tr>
<td>restart</td>
<td>设置重启策略</td>
</tr>
</tbody></table>
<h2 id="创建容器、查看容器"><a href="#创建容器、查看容器" class="headerlink" title="创建容器、查看容器"></a>创建容器、查看容器</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># 创建容器</span>
<span class="token comment"># 会尝试构建镜像、创建容器、启动容器</span>
docker-compose up -d

<span class="token comment"># 查看容器</span>
docker-compose <span class="token function">ps</span>
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="停止、启动、重新构建镜像、查看输出"><a href="#停止、启动、重新构建镜像、查看输出" class="headerlink" title="停止、启动、重新构建镜像、查看输出"></a>停止、启动、重新构建镜像、查看输出</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># 停止容器</span>
<span class="token comment"># 指定容器则关闭指定容器</span>
<span class="token comment"># 不指定容器则关闭所有容器</span>
docker-compose stop 容器名称

<span class="token comment"># 启动容器</span>
<span class="token comment"># 指定容器则启动指定容器</span>
<span class="token comment"># 不指定容器则启动所有容器</span>
docker-compose start 容器名称

<span class="token comment"># 重新构建镜像</span>
<span class="token comment"># 指定镜像则构建指定镜像</span>
<span class="token comment"># 不指定镜像则构建所有镜像</span>
docker-compose build 容器名称

<span class="token comment"># 查看容器输出</span>
docker-compose logs 容器名称
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="搭建-lnmp-环境"><a href="#搭建-lnmp-环境" class="headerlink" title="搭建 lnmp 环境"></a>搭建 lnmp 环境</h2><hr>
<h3 id="文件目录结构"><a href="#文件目录结构" class="headerlink" title="文件目录结构"></a>文件目录结构</h3><pre class="line-numbers language-dockerfile" data-language="dockerfile"><code class="language-dockerfile">├── data
│   └── mysql
├── logs
│   ├── mysql
│   ├── nginx
│   ├── php56
│   └── php74
├── services
│   ├── mysql
│   │   ├── Dockerfile
│   │   └── conf
│   │       ├── conf.d
│   │       │   ├── docker.cnf
│   │       │   └── mysql.cnf
│   │       ├── my.cnf
│   │       └── my.cnf.fallback
│   ├── nginx
│   │   ├── Dockerfile
│   │   └── conf
│   │       ├── cert
│   │       │   ├── www.key
│   │       │   └── www.pem
│   │       ├── fastcgi.conf
│   │       ├── fastcgi_params
│   │       ├── koi-utf
│   │       ├── koi-win
│   │       ├── mime.types
│   │       ├── nginx.conf
│   │       ├── rewrite
│   │       │   └── www.rewrite
│   │       ├── scgi_params
│   │       ├── uwsgi_params
│   │       ├── vhost
│   │       │   └── www.conf
│   │       └── win-utf
│   ├── php56
│   │   ├── Dockerfile
│   │   └── etc
│   │       ├── php
│   │       │   ├── php.ini
│   │       │   ├── php.ini-development
│   │       │   └── php.ini-production
│   │       ├── php-fpm.conf
│   │       ├── php-fpm.conf.default
│   │       └── php-fpm.d
│   │           ├── docker.conf
│   │           ├── www.conf
│   │           └── zz-docker.conf
│   └── php74
│       ├── Dockerfile
│       ├── etc
│       │   ├── php
│       │   │   ├── php.ini
│       │   │   ├── php.ini-development
│       │   │   └── php.ini-production
│       │   ├── php-fpm.conf
│       │   ├── php-fpm.conf.default
│       │   └── php-fpm.d
│       │       ├── docker.conf
│       │       ├── www.conf
│       │       └── zz-docker.conf
│       └── install-php-extensions
└── www
│   └── index.php
├── docker-compose.yml<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h3 id="docker-compose-yml"><a href="#docker-compose-yml" class="headerlink" title="docker-compose.yml"></a>docker-compose.yml</h3><pre class="line-numbers language-yaml" data-language="yaml"><code class="language-yaml"><span class="token key atrule">version</span><span class="token punctuation">:</span> <span class="token string">"3"</span>
<span class="token key atrule">services</span><span class="token punctuation">:</span>
  <span class="token key atrule">nginx</span><span class="token punctuation">:</span>
    <span class="token key atrule">build</span><span class="token punctuation">:</span>
      <span class="token key atrule">context</span><span class="token punctuation">:</span> ./services/nginx
    <span class="token key atrule">container_name</span><span class="token punctuation">:</span> nginx
    <span class="token key atrule">ports</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> <span class="token datetime number">80:80</span>
      <span class="token punctuation">-</span> 443<span class="token punctuation">:</span><span class="token number">443</span>
    <span class="token key atrule">volumes</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> ./www<span class="token punctuation">:</span>/www
      <span class="token punctuation">-</span> ./services/nginx/conf<span class="token punctuation">:</span>/etc/nginx
      <span class="token punctuation">-</span> ./logs/nginx<span class="token punctuation">:</span>/var/log/nginx
    <span class="token key atrule">restart</span><span class="token punctuation">:</span> always
    <span class="token key atrule">depends_on</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> php56
      <span class="token punctuation">-</span> php74
    <span class="token key atrule">environment</span><span class="token punctuation">:</span>
      <span class="token key atrule">TZ</span><span class="token punctuation">:</span> <span class="token string">"Asia/Shanghai"</span>

  <span class="token key atrule">php56</span><span class="token punctuation">:</span>
    <span class="token key atrule">build</span><span class="token punctuation">:</span>
      <span class="token key atrule">context</span><span class="token punctuation">:</span> ./services/php56
    <span class="token key atrule">container_name</span><span class="token punctuation">:</span> php56
    <span class="token key atrule">volumes</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> ./www<span class="token punctuation">:</span>/www
      <span class="token punctuation">-</span> ./services/php56/etc/php/php.ini<span class="token punctuation">:</span>/usr/local/etc/php/php.ini
      <span class="token punctuation">-</span> ./services/php56/etc/php<span class="token punctuation">-</span>fpm.conf<span class="token punctuation">:</span>/usr/local/etc/php<span class="token punctuation">-</span>fpm.conf
      <span class="token punctuation">-</span> ./services/php56/etc/php<span class="token punctuation">-</span>fpm.d<span class="token punctuation">:</span>/usr/local/etc/php<span class="token punctuation">-</span>fpm.d
      <span class="token punctuation">-</span> ./logs/php56<span class="token punctuation">:</span>/var/log/php
    <span class="token key atrule">restart</span><span class="token punctuation">:</span> always
    <span class="token key atrule">depends_on</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> mysql57
    <span class="token key atrule">environment</span><span class="token punctuation">:</span>
      <span class="token key atrule">TZ</span><span class="token punctuation">:</span> <span class="token string">"Asia/Shanghai"</span>

  <span class="token key atrule">php74</span><span class="token punctuation">:</span>
    <span class="token key atrule">build</span><span class="token punctuation">:</span>
      <span class="token key atrule">context</span><span class="token punctuation">:</span> ./services/php74
    <span class="token key atrule">container_name</span><span class="token punctuation">:</span> php74
    <span class="token key atrule">volumes</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> ./www<span class="token punctuation">:</span>/www
      <span class="token punctuation">-</span> ./services/php74/etc/php/php.ini<span class="token punctuation">:</span>/usr/local/etc/php/php.ini
      <span class="token punctuation">-</span> ./services/php74/etc/php<span class="token punctuation">-</span>fpm.conf<span class="token punctuation">:</span>/usr/local/etc/php<span class="token punctuation">-</span>fpm.conf
      <span class="token punctuation">-</span> ./services/php74/etc/php<span class="token punctuation">-</span>fpm.d<span class="token punctuation">:</span>/usr/local/etc/php<span class="token punctuation">-</span>fpm.d
      <span class="token punctuation">-</span> ./logs/php74<span class="token punctuation">:</span>/var/log/php
    <span class="token key atrule">restart</span><span class="token punctuation">:</span> always
    <span class="token key atrule">depends_on</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> mysql57
    <span class="token key atrule">environment</span><span class="token punctuation">:</span>
      <span class="token key atrule">TZ</span><span class="token punctuation">:</span> <span class="token string">"Asia/Shanghai"</span>

  <span class="token key atrule">mysql57</span><span class="token punctuation">:</span>
    <span class="token key atrule">container_name</span><span class="token punctuation">:</span> mysql57
    <span class="token key atrule">build</span><span class="token punctuation">:</span>
      <span class="token key atrule">context</span><span class="token punctuation">:</span> ./services/mysql
      <span class="token key atrule">args</span><span class="token punctuation">:</span>
        <span class="token punctuation">-</span> MYSQL_VER=5.7
    <span class="token key atrule">ports</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> 3306<span class="token punctuation">:</span><span class="token number">3306</span>
    <span class="token key atrule">volumes</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> ./services/mysql/conf<span class="token punctuation">:</span>/etc/mysql
      <span class="token punctuation">-</span> ./data/mysql<span class="token punctuation">:</span>/var/lib/mysql
      <span class="token punctuation">-</span> ./logs/mysql<span class="token punctuation">:</span>/var/log/mysql
    <span class="token key atrule">environment</span><span class="token punctuation">:</span>
      <span class="token key atrule">MYSQL_ROOT_PASSWORD</span><span class="token punctuation">:</span> <span class="token number">123456</span>
    <span class="token key atrule">restart</span><span class="token punctuation">:</span> always
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h3 id="PHP5-6-Dockerfile"><a href="#PHP5-6-Dockerfile" class="headerlink" title="PHP5.6 Dockerfile"></a>PHP5.6 Dockerfile</h3><pre class="line-numbers language-dockerfile" data-language="dockerfile"><code class="language-dockerfile"># 基础镜像
FROM php:5.6-fpm-alpine

# 修改系统镜像源、安装依赖
RUN sed -i &quot;s&#x2F;dl-cdn.alpinelinux.org&#x2F;mirrors.aliyun.com&#x2F;g&quot; &#x2F;etc&#x2F;apk&#x2F;repositories \
  &amp;&amp; apk update \
  &amp;&amp; apk --no-cache add tzdata \
  &amp;&amp; cp &quot;&#x2F;usr&#x2F;share&#x2F;zoneinfo&#x2F;Asia&#x2F;Shanghai&quot; &#x2F;etc&#x2F;localtime \
  &amp;&amp; echo &quot;Asia&#x2F;Shanghai&quot; &gt; &#x2F;etc&#x2F;timezone \
  &amp;&amp; apk add --no-cache --virtual .build-deps autoconf g++ libtool make linux-headers bzip2-dev libzip-dev

# 扩展脚本-用于安装PHP扩展
ADD ADD https:&#x2F;&#x2F;github.com&#x2F;mlocati&#x2F;docker-php-extension-installer&#x2F;releases&#x2F;latest&#x2F;download&#x2F;install-php-extensions &#x2F;usr&#x2F;local&#x2F;bin&#x2F;

# 安装 PHP 扩展
RUN chmod +x &#x2F;usr&#x2F;local&#x2F;bin&#x2F;install-php-extensions &amp;&amp; sync &amp;&amp; \
    install-php-extensions rdkafka pcntl swoole redis bcmath bz2 gd \
    gettext imagick mcrypt memcached mongodb mysqli pcntl \
    pdo_mysql shmop soap sockets sysvmsg sysvsem sysvshm xdebug \
    xmlrpc zip mysql

# 安装 PHP 分词扩展
RUN mkdir &#x2F;tmp&#x2F;extensions
WORKDIR &#x2F;tmp&#x2F;extensions
RUN mkdir &#x2F;tmp&#x2F;scws \
    &amp;&amp; wget http:&#x2F;&#x2F;www.xunsearch.com&#x2F;scws&#x2F;down&#x2F;scws-1.2.3.tar.bz2 \
    &amp;&amp; tar -xjf &#x2F;tmp&#x2F;extensions&#x2F;scws-1.2.3.tar.bz2 -C &#x2F;tmp&#x2F;scws --strip-components&#x3D;1 \
    &amp;&amp; cd &#x2F;tmp&#x2F;scws  \
    &amp;&amp; .&#x2F;configure --prefix&#x3D;&#x2F;usr&#x2F;local&#x2F;scws  \
    &amp;&amp; make &amp;&amp; make install  \
    &amp;&amp; ( cd phpext &amp;&amp; phpize &amp;&amp; .&#x2F;configure --with-scws&#x3D;&#x2F;usr&#x2F;local&#x2F;scws &amp;&amp; make &amp;&amp; make install ) \
    &amp;&amp; cd &#x2F;usr&#x2F;local&#x2F;scws&#x2F;etc \
    &amp;&amp; wget http:&#x2F;&#x2F;www.xunsearch.com&#x2F;scws&#x2F;down&#x2F;scws-dict-chs-gbk.tar.bz2 \
    &amp;&amp; wget http:&#x2F;&#x2F;www.xunsearch.com&#x2F;scws&#x2F;down&#x2F;scws-dict-chs-utf8.tar.bz2 \
    &amp;&amp; tar -xvjf scws-dict-chs-gbk.tar.bz2 \
    &amp;&amp; tar -xvjf scws-dict-chs-utf8.tar.bz2 \
    &amp;&amp; docker-php-ext-enable scws \
    &amp;&amp; rm -rf &#x2F;tmp&#x2F;*

ENV LD_PRELOAD &#x2F;usr&#x2F;lib&#x2F;preloadable_libiconv.so php<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h3 id="PHP7-4-Dockerfile"><a href="#PHP7-4-Dockerfile" class="headerlink" title="PHP7.4 Dockerfile"></a>PHP7.4 Dockerfile</h3><pre class="line-numbers language-dockerfile" data-language="dockerfile"><code class="language-dockerfile"># 基础镜像
FROM php:7.4-fpm-alpine

# 修改系统镜像源、安装依赖
RUN sed -i &quot;s&#x2F;dl-cdn.alpinelinux.org&#x2F;mirrors.aliyun.com&#x2F;g&quot; &#x2F;etc&#x2F;apk&#x2F;repositories \
  &amp;&amp; apk update \
  &amp;&amp; apk --no-cache add tzdata \
  &amp;&amp; cp &quot;&#x2F;usr&#x2F;share&#x2F;zoneinfo&#x2F;Asia&#x2F;Shanghai&quot; &#x2F;etc&#x2F;localtime \
  &amp;&amp; echo &quot;Asia&#x2F;Shanghai&quot; &gt; &#x2F;etc&#x2F;timezone \
  &amp;&amp; apk add --no-cache --virtual .build-deps autoconf g++ libtool make linux-headers bzip2-dev libzip-dev

# 扩展脚本-用于安装PHP扩展
ADD ADD https:&#x2F;&#x2F;github.com&#x2F;mlocati&#x2F;docker-php-extension-installer&#x2F;releases&#x2F;latest&#x2F;download&#x2F;install-php-extensions &#x2F;usr&#x2F;local&#x2F;bin&#x2F;

# 安装 PHP 扩展
RUN chmod +x &#x2F;usr&#x2F;local&#x2F;bin&#x2F;install-php-extensions &amp;&amp; sync &amp;&amp; \
    install-php-extensions rdkafka pcntl swoole redis bcmath bz2 gd \
    gettext imagick mcrypt memcached mongodb mysqli pcntl \
    pdo_mysql shmop soap sockets sysvmsg sysvsem sysvshm xdebug \
    xmlrpc zip

# 安装 PHP 分词扩展
RUN mkdir &#x2F;tmp&#x2F;extensions
WORKDIR &#x2F;tmp&#x2F;extensions
RUN mkdir &#x2F;tmp&#x2F;scws \
    &amp;&amp; wget http:&#x2F;&#x2F;www.xunsearch.com&#x2F;scws&#x2F;down&#x2F;scws-1.2.3.tar.bz2 \
    &amp;&amp; tar -xjf &#x2F;tmp&#x2F;extensions&#x2F;scws-1.2.3.tar.bz2 -C &#x2F;tmp&#x2F;scws --strip-components&#x3D;1 \
    &amp;&amp; cd &#x2F;tmp&#x2F;scws  \
    &amp;&amp; .&#x2F;configure --prefix&#x3D;&#x2F;usr&#x2F;local&#x2F;scws  \
    &amp;&amp; make &amp;&amp; make install  \
    &amp;&amp; ( cd phpext &amp;&amp; phpize &amp;&amp; .&#x2F;configure --with-scws&#x3D;&#x2F;usr&#x2F;local&#x2F;scws &amp;&amp; make &amp;&amp; make install ) \
    &amp;&amp; cd &#x2F;usr&#x2F;local&#x2F;scws&#x2F;etc \
    &amp;&amp; wget http:&#x2F;&#x2F;www.xunsearch.com&#x2F;scws&#x2F;down&#x2F;scws-dict-chs-gbk.tar.bz2 \
    &amp;&amp; wget http:&#x2F;&#x2F;www.xunsearch.com&#x2F;scws&#x2F;down&#x2F;scws-dict-chs-utf8.tar.bz2 \
    &amp;&amp; tar -xvjf scws-dict-chs-gbk.tar.bz2 \
    &amp;&amp; tar -xvjf scws-dict-chs-utf8.tar.bz2 \
    &amp;&amp; docker-php-ext-enable scws \
    &amp;&amp; rm -rf &#x2F;tmp&#x2F;*

ENV LD_PRELOAD &#x2F;usr&#x2F;lib&#x2F;preloadable_libiconv.so php<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h3 id="Nginx-Dockerfile"><a href="#Nginx-Dockerfile" class="headerlink" title="Nginx Dockerfile"></a>Nginx Dockerfile</h3><pre class="line-numbers language-dockerfile" data-language="dockerfile"><code class="language-dockerfile"># 基础镜像
FROM nginx:alpine

# 修改系统镜像源、安装依赖
RUN sed -i &quot;s&#x2F;dl-cdn.alpinelinux.org&#x2F;mirrors.aliyun.com&#x2F;g&quot; &#x2F;etc&#x2F;apk&#x2F;repositories \
  &amp;&amp; apk --no-cache add tzdata \
  &amp;&amp; cp &quot;&#x2F;usr&#x2F;share&#x2F;zoneinfo&#x2F;Asia&#x2F;Shanghai&quot; &#x2F;etc&#x2F;localtime \
  &amp;&amp; echo &quot;Asia&#x2F;Shanghai&quot; &gt; &#x2F;etc&#x2F;timezone
  <span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h3 id="Mysql-Dockerfile"><a href="#Mysql-Dockerfile" class="headerlink" title="Mysql Dockerfile"></a>Mysql Dockerfile</h3><pre class="line-numbers language-dockerfile" data-language="dockerfile"><code class="language-dockerfile"># mysql 版本变量
ARG MYSQL_VER

# 基础镜像
FROM mysql:$&#123;MYSQL_VER&#125;

# 设置时区为上海
ENV TZ&#x3D;Asia&#x2F;Shanghai
RUN ln -snf &#x2F;usr&#x2F;share&#x2F;zoneinfo&#x2F;$TZ &#x2F;etc&#x2F;localtime &amp;&amp; echo $TZ &gt; &#x2F;etc&#x2F;timezone

# Ubuntu软件源选择中国的服务器
RUN sed -i &#39;s&#x2F;archive.ubuntu.com&#x2F;mirrors.aliyun.com&#x2F;g&#39; &#x2F;etc&#x2F;apt&#x2F;sources.list

# 更新安装依赖包
RUN apt-get update &amp;&amp; apt-get install -y vim wget<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>



    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/lnmp/" rel="tag"># lnmp</a>
              <a href="/tags/docker-compose/" rel="tag"># docker-compose</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/03/27/docker/docker-container-chang-yong-ming-ling/" rel="prev" title="Docker-Container 常用命令">
      <i class="fa fa-chevron-left"></i> Docker-Container 常用命令
    </a></div>
      <div class="post-nav-item"></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#docker-compose-yml-%E6%96%87%E4%BB%B6%E9%83%A8%E5%88%86%E5%91%BD%E4%BB%A4%E8%AF%B4%E6%98%8E"><span class="nav-number">1.</span> <span class="nav-text">docker-compose.yml 文件部分命令说明</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E5%AE%B9%E5%99%A8%E3%80%81%E6%9F%A5%E7%9C%8B%E5%AE%B9%E5%99%A8"><span class="nav-number">2.</span> <span class="nav-text">创建容器、查看容器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%81%9C%E6%AD%A2%E3%80%81%E5%90%AF%E5%8A%A8%E3%80%81%E9%87%8D%E6%96%B0%E6%9E%84%E5%BB%BA%E9%95%9C%E5%83%8F%E3%80%81%E6%9F%A5%E7%9C%8B%E8%BE%93%E5%87%BA"><span class="nav-number">3.</span> <span class="nav-text">停止、启动、重新构建镜像、查看输出</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%90%AD%E5%BB%BA-lnmp-%E7%8E%AF%E5%A2%83"><span class="nav-number">4.</span> <span class="nav-text">搭建 lnmp 环境</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%96%87%E4%BB%B6%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84"><span class="nav-number">4.1.</span> <span class="nav-text">文件目录结构</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#docker-compose-yml"><span class="nav-number">4.2.</span> <span class="nav-text">docker-compose.yml</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#PHP5-6-Dockerfile"><span class="nav-number">4.3.</span> <span class="nav-text">PHP5.6 Dockerfile</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#PHP7-4-Dockerfile"><span class="nav-number">4.4.</span> <span class="nav-text">PHP7.4 Dockerfile</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Nginx-Dockerfile"><span class="nav-number">4.5.</span> <span class="nav-text">Nginx Dockerfile</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Mysql-Dockerfile"><span class="nav-number">4.6.</span> <span class="nav-text">Mysql Dockerfile</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">he7009</p>
  <div class="site-description" itemprop="description">Go、PHP、Mysql、Redis、Linux、Shell、Nginx—知识分享</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">9</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">12</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">he7009</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://mist.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
